<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>

description("This tests the constructor for the FocusEvent DOM class.");

var testObject = {nyannyan: 123};
var testDiv = document.createElement("div");
var xhr = new XMLHttpRequest;

// No initializer is passed.
shouldBe("new FocusEvent('eventType').bubbles", "false");
shouldBe("new FocusEvent('eventType').cancelable", "false");
shouldBe("new FocusEvent('eventType').view", "null");
shouldBe("new FocusEvent('eventType').detail", "0");
shouldBe("new FocusEvent('eventType').relatedTarget", "null");

// bubbles is passed.
shouldBe("new FocusEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new FocusEvent('eventType', { bubbles: true }).bubbles", "true");

// cancelable is passed.
shouldBe("new FocusEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new FocusEvent('eventType', { cancelable: true }).cancelable", "true");

// view is passed.
// Window objects.
shouldBe("new FocusEvent('eventType', { view: window }).view", "window");
shouldBe("new FocusEvent('eventType', { view: this }).view", "this");

// Non-window objects.
shouldThrow("new FocusEvent('eventType', { view: testObject }).view");
shouldThrow("new FocusEvent('eventType', { view: document }).view");
shouldBe("new FocusEvent('eventType', { view: undefined }).view", "null");
shouldBe("new FocusEvent('eventType', { view: null }).view", "null");
shouldThrow("new FocusEvent('eventType', { view: false }).view");
shouldThrow("new FocusEvent('eventType', { view: true }).view");
shouldThrow("new FocusEvent('eventType', { view: '' }).view");
shouldThrow("new FocusEvent('eventType', { view: 'chocolate' }).view");
shouldThrow("new FocusEvent('eventType', { view: 12345 }).view");
shouldThrow("new FocusEvent('eventType', { view: 18446744073709551615 }).view");
shouldThrow("new FocusEvent('eventType', { view: NaN }).view");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
shouldBe("new FocusEvent('eventType', { get view() { return window; } }).view", "window");
shouldThrow("new FocusEvent('eventType', { get view() { return 123; } }).view");
shouldThrow("new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } })");

// relatedTarget is passed.
// Valid objects.
shouldBe("new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
shouldBe("new FocusEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
shouldBe("new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
shouldBe("new FocusEvent('eventType', { relatedTarget: window }).relatedTarget", "window");

// Invalid objects.
shouldThrow("new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget");
shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
shouldThrow("new FocusEvent('eventType', { relatedTarget: false }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: true }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
shouldBeTrue("new FocusEvent('eventType', { get relatedTarget() { return testDiv; } }).relatedTarget == testDiv");
shouldThrow("new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget");
shouldThrow("new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } })");

// All initializers are passed.
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles", "true");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable", "true");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view", "window");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail", "111");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget", "testDiv");
</script>
</body>
</html>
